package com.demo.service;


import com.demo.dao.OrderMapper;
import com.demo.model.Order;
import com.demo.model.Searches;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Demo1Service {

  @Autowired
  private OrderMapper orderMapper;

  public String demo1(){

    try {

      for (int i = 0; i < 100; i++) {

        Order order = new Order();
        order.setName("电脑"+i);
        order.setType("开发票");

        orderMapper.insertSelective(order);
      }



      return "demo1";
    }catch (Exception ex){
      ex.printStackTrace();
      throw ex;
    }

  }



  public void demo2(String id){


    Order order = orderMapper.selectByPrimaryKey(Long.valueOf(id));

    System.out.println(order.toString());


  }


  public PageInfo<Order> demo3(Searches searches){

    PageHelper.startPage(searches.getPage().getPageNum(),searches.getPage().getPageSize());

    List<Order> searches1 = orderMapper.searches();

    return new PageInfo<>(searches1);

  }


}
